<style lang="less">
@import "./login.less";
</style>

<template>
  <div class="login">
    <div class="login-con">
      <div class="form-con" style="padding: 16px">
        <div class="form-title">
          <p class="cn-title">用户登录</p>
          <p class="en-title">USER LOGIN</p>
        </div>
        <login-form @on-success-valid="handleSubmit"></login-form>
      </div>
    </div>
  </div>
</template>

<script>
import LoginForm from '_c/login-form'
import Secret from '../../libs/util/secret.js'
import { mapActions } from 'vuex'
export default {
  components: {
    LoginForm
  },
  methods: {
    ...mapActions([
      'handleLogin',
      'getMenus',
      'getMainReportData',
      'getAccountBalanceData'
    ]),
    async handleSubmit ({ userName, password, remebered }) {
      const resp = await this.handleLogin({ userName, password })
      if (resp.state === '000') {
        if (remebered) {
          const username = Secret.Encrypt(userName)
          const pws = Secret.Encrypt(password)
          localStorage.setItem('username', username)
          localStorage.setItem('pws', pws)
        } else {
          localStorage.removeItem('username')
          localStorage.removeItem('pws')
        }
        this.getMenus().then(res => {
          if (res.state === '000') {
            console.log(this.$config.homeName)
            this.$router.push({
              name: this.$config.homeName
            })
          } else {
            this.$Message.error(res.data.msg)
          }
        })
      } else {
        this.$Message.error(resp.msg)
      }
    }
  }
}
</script>

<style>
</style>
